home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / pointMatrixMult.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.7 KB  |  108 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. // Copyright (C) 1997-1999 Alias|Wavefront,
  18. // a division of Silicon Graphics Limited.
  19. //
  20. // The information in this file is provided for the exclusive use of the
  21. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  22. // and incorporate this code into other products for purposes authorized
  23. // by the Alias|Wavefront license agreement, without fee.
  24. //
  25. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  26. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  27. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  28. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  29. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  30. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  31. // PERFORMANCE OF THIS SOFTWARE.
  32. //
  33. //
  34. // Alias|Wavefront Script File
  35. // MODIFY THIS AT YOUR OWN RISK
  36. // Creation Date: June 30 1998
  37. //
  38. //<doc>
  39. //<name pointMatrixMult>
  40. //<owner "Alias|Wavefront Unsupported">
  41. //
  42. //<synopsis>
  43. //    float[] pointMatrixMult ( float $point[], float $matrix[] )
  44. //
  45. //<description>
  46. //      This script returns the multiplication of a point and a 
  47. //        matrix as an array of 3 doubles:
  48. //<pre>
  49. //      vector * matrix = result
  50. //</pre>
  51. //<P>
  52. //        <b>Note:</b> The matrix is assumed to be a single dimension
  53. //        array of 16 elements.
  54. //<BR>
  55. //        <b>Remember:</b> That the arrays are 0-based.
  56. //        e.g. [1][0] is matrix[4] element
  57. //
  58. //<flags>
  59. //        float $point[]    Co-ordinates of the point.
  60. //        float $matrix[]    The matrix to be used.
  61. //
  62. //<returns>
  63. //        float[] : Result as an array of 3 doubles.
  64. //
  65. //</doc>
  66. //
  67.  
  68. global proc float[] pointMatrixMult( float $point[], float $matrix[] )
  69. //
  70. //     Description:
  71. //         Multiplies a point by a matrix and returns the result. 
  72. //
  73. {
  74.     float $result[];
  75.  
  76.     $result[0] = 0.0;
  77.     $result[1] = 0.0;
  78.     $result[2] = 0.0;
  79.  
  80.     if ( size($point) != 3 || size($matrix) != 16 )
  81.     {
  82.         warning("Point must be an array of 3 doubles and matrix must be an array of 16 doubles.");
  83.         return $result;
  84.     }
  85.  
  86.     // create the node that will do the actual computation
  87.     //
  88.     string $multNode;
  89.     if ( catch($multNode = `createNode pointMatrixMult`) ) 
  90.     {
  91.         warning("Could not create pointMatrixMult node.");
  92.         return $result;
  93.     }
  94.  
  95.     // set the matrix and point inputs to the node
  96.     //
  97.     setAttr ($multNode+".vectorMultiply") true;
  98.     setAttr ($multNode+".inPoint") -type "double3" $point[0] $point[1] $point[2];
  99.     setAttr ($multNode+".inMatrix") -type "matrix" $matrix[0] $matrix[1] $matrix[2] $matrix[3] $matrix[4] $matrix[5] $matrix[6] $matrix[7] $matrix[8] $matrix[9] $matrix[10] $matrix[11] $matrix[12] $matrix[13] $matrix[14] $matrix[15];
  100.  
  101.     // get the result and delete the node since it is no longer required
  102.     //
  103.     $result = `getAttr ($multNode+".output")`;
  104.     delete $multNode;
  105.  
  106.     return $result;
  107. }
  108.